//
//  SkinTools.swift
//  ChangeSkin
//
//  Created by Lenhulk on 2016/11/20.
//  Copyright © 2016年 Lenhulk. All rights reserved.
//

import UIKit

private let kSkinKey = "kSkinKey"

class SkinTools: NSObject {
    
    //定义皮肤名称, 启动后偏好设置取皮肤, 若为nil, 默认皮肤为"春节"
    static var skinName = (UserDefaults.standard.object(forKey: kSkinKey) as? String) ?? "chunjie"
}

extension SkinTools {
    
    ///根据需要的类型返回主题的元素(图片)
    class func imageName(_ typeName : String) -> UIImage? {
        return UIImage(named: "Skin/\(skinName)/\(typeName)")
    }
    
    ///定义主题名,保存到偏好设置
    class func setCurrentSkinName(_ curSkin : String) {
        self.skinName = curSkin
        UserDefaults.standard.set(skinName, forKey: kSkinKey)
        UserDefaults.standard.synchronize()     //立即上传
    }
    
    ///修改Label背景颜色
    class func labelBgColor() -> UIColor{
        switch skinName {
        case "chunjie":
            return .red
        case "zhongqiu":
            return .brown
        case "guoqing":
            return .orange
        default:
            return .white
        }
    }
}
